<?php $this->set('title_for_layout', 'The best free post advertising in Cambodia | Free Market | Online Market'); ?>
<div class="col-sm-12 free-ads" style="border: 1px solid #D0D0D0;">
    <a href="<?php echo $this->webroot; ?>products/add"><img src="<?php echo $this->webroot; ?>img/click-here.jpg" /></a>
</div>
<div class="clearfix"></div>
<div class="content_ads">
    <?php
        echo $this->element('top_content_ads');
    ?>
</div>
<div>
    <?php if($productPromotions){?>
      <ul id="flexiselDemo3">
          
        <?php foreach ($productPromotions as $promotion):
                echo '<li style="width: 200px;">';
                $image=$promotion['Product']['picture1'];
                if(empty($image)){
                    $image = 'default_product.png';
                    $resizedFile = 'img/uploads/'.$image;
                }else {
                   $resizedFile = 'img/uploads/images_resize/'.$image;
                }
                echo '<a href="posts/view/'.$promotion['Product']['id'].'"><i class="'.$promotion['Product']['type'].'"></i><img style="width: 100px; "src="'.$resizedFile.'"/></a>';
                if (strlen($promotion['Product']['title']) > 10) {
                    echo '<span class="pro-title">'.$this->Html->link(substr($promotion['Product']['title'], 0, 10).'...', array('controller' => 'posts', 'action' => 'view', $promotion['Product']['id'])).'</span>';
                }else {
                    echo '<span class="pro-title">'.$this->Html->link($promotion['Product']['title'], array('controller' => 'posts', 'action' => 'view', $promotion['Product']['id'])).'</span>';
                }
                echo '<span id="pro-price">$'.$promotion['Product']['price'].'<i class="'.$promotion['Product']['status'].'"></i></span>';
                echo '<span id="auth">'.$promotion['Product']['name'].'</span><br>';
                if($promotion['Location']['name']) {echo '<span id="address">'.$promotion['Location']['name'].'</span><br>';}
                echo '<span id="phone">'.$promotion['Product']['phone'].'</span><br>';
                echo '</li>';
        endforeach;?>
        </ul>
    <?php }?>
<!--    <div class="clearout"></div>-->
</div>

<div class="content_ads">
    <?php
        echo $this->element('middle_content_ads');
    ?>
</div>
<div class="latest">
		<div class="list-group product-list">
<!--                    <h3 class="list-group-item"><i class="latest-icon"></i>Latest Ads <a href="" class="btn" id="view_all"><i class="view-all"></i>view all</a></h3>-->
                    
                    <?php 
                        echo '<h3 class="list-group-item"><i class="latest-icon"></i>Latest Ads';
                        echo '<span class="btn view-all">'.$this->Html->link('view all', array('controller' => 'posts', 'action' => 'allads')).'</span></h3>';
                    ?>
		<div class="list-group-item">
		<?php 
                    foreach ($products as $product):
                        echo '<div class="item">';
                            $image=$product['Product']['picture1'];
                            if(empty($image)){
                                $image = 'default_product.png';
                                $resizedFile = $this->webroot.'img/uploads/'.$image;
                            }else {
                               $resizedFile = $this->webroot.'img/uploads/images_resize/'.$image;
                            }
                            echo '<a href="posts/view/'.$product['Product']['id'].'"><img style="width: 100px; height: 100px; "src="'.$resizedFile.'"/></a>';
                            
                            
                            if (strlen($product['Product']['title']) > 10) {
                                echo '<span class="pro-title">'.$this->Html->link(substr(strip_tags($product['Product']['title']), 0, 10).'...', array('controller' => 'posts', 'action' => 'view', $product['Product']['id'])).'</span>';
                            }else {
                                echo '<span class="pro-title">'.$this->Html->link($product['Product']['title'], array('controller' => 'posts', 'action' => 'view', $product['Product']['id'])).'</span>';
                            }
                            
                            echo '<span id="pro-price">$'.$product['Product']['price'].'<i class="'.$product['Product']['status'].'"></i></span>';
                            echo '<span id="auth">'.$product['Product']['name'].'</span><br>';
                            if($product['Location']['name']) {echo '<span id="address">'.$product['Location']['name'].'</span><br>';}
                            echo '<span id="phone">'.$product['Product']['phone'].'</span><br>';
                            echo '</div>';
                    endforeach;
                ?>
		</div>
    </div>
</div>
<ul class="nav nav-tabs" id="product_tabs">
	<li class="active header-side"><a href="#featured_products" data-toggle="tab">Featured Products</a></li>
	
        <li class="header-side"><a href="#popular_product" data-toggle="tab">Popular Product</a></li>
        <li class="header-side"><a href="#products_sale" data-toggle="tab">Sale/Buy</a></li>
</ul>
<div class="tab-content">
	<div class="tab-pane active" id="featured_products">
            <?php
                //print_r($counttoday);
            ?>
		<?php foreach ($feartureproducts as $product):
			echo '<div class="item">';
                        $image=$product['Product']['picture1'];
			if(empty($image)){
                            $image = 'default_product.png';
                            $resizedFile = 'img/uploads/'.$image;
                        }else {
                           $resizedFile = 'img/uploads/images_resize/'.$image;
                        }
			echo '<a href="posts/view/'.$product['Product']['id'].'"><img style="width: 100px; "src="'.$resizedFile.'"/></a>';
			if (strlen($product['Product']['title']) > 30) {
                            echo '<span class="pro-title">'.$this->Html->link(substr($product['Product']['title'], 0, 30).'...', array('controller' => 'posts', 'action' => 'view', $product['Product']['id'])).'</span>';
                        }else {
                            echo '<span class="pro-title">'.$this->Html->link($product['Product']['title'], array('controller' => 'posts', 'action' => 'view', $product['Product']['id'])).'</span>';
                        }
			echo '<span id="pro-price">$'.$product['Product']['price'].'<i class="'.$product['Product']['status'].'"></i></span>';
			echo '<span id="modified_date">'.$product['Product']['modified_date'].'</span>';
                       echo '<span id="auth">'.$product['Product']['name'].'</span>';
                        if($product['Location']['name']) {echo '<span id="address">'.$product['Location']['name'].'</span>';}
			echo '<span id="phone">'.$product['Product']['phone'].'</span><br>';
                        
			if (strlen($product['Product']['description']) > 150) {
                            echo '<span id="dec">'.substr(strip_tags($product['Product']['description']), 0, 150).'...'.'</span>';
                        }else {
                            echo '<span id="dec">'.$product['Product']['description'].'</span>';
                        }
                        
                        echo '<div class="total-view">';
                       ?> <a href="#" class="<?php echo $product['Product']['id']; ?>"></a><a href="#" id="<?php echo $product['Product']['id']; ?>" data="<?php echo $product['Product']['id'] ?>" class="favorite"></a><?php
                        if($product['Product']['view']) {
                            echo '<span class="total-product">View :'.$product['Product']['view'].'</span>';
                        }else {
                            echo '<span class="total-product">View : 0</span>';
                        }
                        $i = 0;
                        for($a=1; $a<=4; $a++){
                            $picture = "picture$a";
                            if($product['Product'][$picture]){
                                $i++;
                            }
                        }
                        echo '<span class="total-image">'.$i.'</span>';
                       
                        echo '<span class="total-comment">'.count($product['Comment']).'</span>';
                        $total = 0;
//                        foreach ($counttoday as $today) {
//                            if($product['Product']['id'] == $today['Statistic']['product_id']) {
//                                $total = $today['Statistic']['count'];
//                            }
//                        }
//                        echo '<apan class="total-today"> Today viewed:'.$total.'</span>';
                        echo '</div>';
			echo '<div class="clearfix"></div></div>';
		endforeach;?>
	</div>
	
        <div class="tab-pane" id="popular_product">
		<?php foreach ($popularProducts as $productPopular):
			echo '<div class="item">';
                        $image=$productPopular['Product']['picture1'];
			if(empty($image)){
                            $image = 'default_product.png';
                            $resizedFile = 'img/uploads/'.$image;
                        }else {
                           $resizedFile = 'img/uploads/images_resize/'.$image;
                        }
			echo '<a href="posts/view/'.$productPopular['Product']['id'].'"><img style="width: 100px; "src="'.$resizedFile.'"/></a>';
			if (strlen($productPopular['Product']['title']) > 30) {
                            echo '<span class="pro-title">'.$this->Html->link(substr($productPopular['Product']['title'], 0, 30).'...', array('controller' => 'posts', 'action' => 'view', $productPopular['Product']['id'])).'</span>';
                        }else {
                            echo '<span class="pro-title">'.$this->Html->link($productPopular['Product']['title'], array('controller' => 'posts', 'action' => 'view', $productPopular['Product']['id'])).'</span>';
                        }
			echo '<span id="pro-price">$'.$productPopular['Product']['price'].'<i class="'.$productPopular['Product']['status'].'"></i></span>';
			echo '<span id="modified_date">'.$productPopular['Product']['modified_date'].'</span>';
                       echo '<span id="auth">'.$productPopular['Product']['name'].'</span>';
                        if($productPopular['Location']['name']) {echo '<span id="address">'.$productPopular['Location']['name'].'</span>';}
			echo '<span id="phone">'.$productPopular['Product']['phone'].'</span><br>';
                        if (strlen($productPopular['Product']['description']) > 150) {
                            echo '<span id="dec">'.substr(strip_tags($productPopular['Product']['description']), 0, 150).'...'.'</span>';
                        }else {
                            echo '<span id="dec">'.$productPopular['Product']['description'].'</span>';
                        }
                         
                        echo '<div class="total-view">';
                        ?> <a href="#" class="popular-<?php echo $productPopular['Product']['id']; ?>"></a><a href="#" id="popular-<?php echo $productPopular['Product']['id']; ?>" data="<?php echo $productPopular['Product']['id'] ?>" class="favorite"></a><?php
                       
                        if($productPopular['Product']['view']) {
                            echo '<span class="total-product">View :'.$productPopular['Product']['view'].'</span>';
                        }else {
                            echo '<span class="total-product">View : 0</span>';
                        }
                        $i = 0;
                        for($a=1; $a<=4; $a++){
                            $picture = "picture$a";
                            if($productPopular['Product'][$picture]){
                                $i++;
                            }
                        }
                        echo '<span class="total-image">'.$i.'</span>';
                       
                        echo '<span class="total-comment">'.count($productPopular['Comment']).'</span>';
                        $total = 0;
//                        foreach ($counttoday as $today) {
//                            if($productPopular['Product']['id'] == $today['Statistic']['product_id']) {
//                                $total = $today['Statistic']['count'];
//                            }
//                        }
//                        echo '<apan class="total-today"> Today viewed:'.$total.'</span>';
                        echo '</div>';
			echo '<div class="clearfix"></div></div>';
		endforeach;?>
	</div><div class="tab-pane" id="products_sale">
		<?php foreach ($productsale as $product):
			echo '<div class="item">';
                        $image=$product['Product']['picture1'];
			if(empty($image)){
                            $image = 'default_product.png';
                            $resizedFile = 'img/uploads/'.$image;
                        }else {
                           $resizedFile = 'img/uploads/images_resize/'.$image;
                        }
			echo '<a href="posts/view/'.$product['Product']['id'].'"><img style="width: 100px; "src="'.$resizedFile.'"/></a>';
			if (strlen($product['Product']['title']) > 30) {
                            echo '<span class="pro-title">'.$this->Html->link(substr($product['Product']['title'], 0, 30).'...', array('controller' => 'posts', 'action' => 'view', $product['Product']['id'])).'</span>';
                        }else {
                            echo '<span class="pro-title">'.$this->Html->link($product['Product']['title'], array('controller' => 'posts', 'action' => 'view', $product['Product']['id'])).'</span>';
                        }
			echo '<span id="pro-price">$'.$product['Product']['price'].'<i class="'.$product['Product']['status'].'"></i></span>';
			echo '<span id="modified_date">'.$product['Product']['modified_date'].'</span>';
                        echo '<span id="auth">'.$product['Product']['name'].'</span>';
                        if($product['Location']['name']) {echo '<span id="address">'.$product['Location']['name'].'</span>';}
			echo '<span id="phone">'.$product['Product']['phone'].'</span><br>';
                        
			if (strlen($product['Product']['description']) > 150) {
                            echo '<span id="dec">'.substr($product['Product']['description'], 0, 150).'...'.'</span>';
                        }else {
                            echo '<span id="dec">'.$product['Product']['description'].'</span>';
                        }
                        
                         echo '<div class="total-view">';
                           
                         ?> <a href="#" class="sale-<?php echo $product['Product']['id']; ?>"></a><a href="#" id="sale-<?php echo $product['Product']['id']; ?>" data="<?php echo $product['Product']['id'] ?>" class="favorite"></a><?php
                         
                        if($product['Product']['view']) {
                            echo '<span class="total-product">View :'.$product['Product']['view'].'</span>';
                        }else {
                            echo '<span class="total-product">View : 0</span>';
                        }
                        $i = 0;
                        for($a=1; $a<=4; $a++){
                            $picture = "picture$a";
                            if($product['Product'][$picture]){
                                $i++;
                            }
                        }
                        echo '<span class="total-image">'.$i.'</span>';
                       
                        echo '<span class="total-comment">'.count($product['Comment']).'</span>';
                        $total = 0;
//                        foreach ($counttoday as $today) {
//                            if($product['Product']['id'] == $today['Statistic']['product_id']) {
//                                $total = $today['Statistic']['count'];
//                            }
//                        }
//                        echo '<apan class="total-today"> Today viewed:'.$total.'</span>';
                        echo '</div>';
			echo '<div class="clearfix"></div></div>';
		endforeach;?>
	</div>
    
</div>
<div class="content_ads">
    <?php
        echo $this->element('bottom_content_ads');
    ?>
</div>
<div id="social_media_tap">
    <ul class="nav nav-tabs" id="social_tab">
        <li class="active header-side ads-partner"><a href="#ads_partner" data-toggle="tab">Ads Partners</a></li>
	<li class="header-side"><a href="#social_facebook" data-toggle="tab">Facebook</a></li>
	<li class="header-side"><a href="#social_google_plus" data-toggle="tab">Google+</a></li>
        <li class="header-side"><a href="#social_twitter" data-toggle="tab">Twitter</a></li>
        <li class="header-side"><a href="#social_linkedin" data-toggle="tab">Linkedin</a></li>
        <li class="header-side"><a href="#visitor_counter" data-toggle="tab">Visitor Counter</a></li>
</ul>
<div class="tab-content">
         <div class="tab-pane active" id="ads_partner">
		<div>
                    <ul id="partner">
                      <?php foreach ($partners as $partner):
                              echo '<li style="width: 200px;">';
                              $image=$partner['Partner']['logo'];
                              $link=$partner['Partner']['alterative'];
                              if(empty($image)){
                                  $image = 'default_product.png';
                              }
                                  $resizedFile = 'img/partners/'.$image;
                              if(empty($link)){
                                  $link = '#';
                              }
                              echo '<a href="'.$link.'" target="_blank"><img style="width: 100px; "src="'.$resizedFile.'" alt="'.$partner['Partner']['alterative'].'"/>';
                              echo '<p>'.$partner['Partner']['name'].'</p></a>';
                              echo '</li>';
                      endforeach;?>
                      </ul>
                  
              </div>
	</div>
	<div class="tab-pane" id="social_facebook">
            <div class="fb-like-box" data-href="https://www.facebook.com/phsarkhmer.biz" data-width="620" data-colorscheme="light" data-show-faces="true" data-header="false" data-stream="false" data-show-border="true"></div>
	</div>
	<div class="tab-pane" id="social_google_plus">
		google plus
	</div>
        <div class="tab-pane" id="social_twitter">
		<a class="twitter-timeline" data-dnt="true" href="https://twitter.com/phsarkhmer" data-widget-id="442516709652439040">Tweets by @phsarkhmer</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
	</div>
        <div class="tab-pane" id="social_linkedin">
		<script src="//platform.linkedin.com/in.js" type="text/javascript">
  lang: en_US
</script>
<script type="IN/Share" data-url="www.linkedin.com/in/phsarkhmer/" data-counter="top"></script>
	</div>
        <div class="tab-pane" id="visitor_counter">
		<?php $this->Counter->_constructDB();  ?>
	</div>
</div>
</div>
